import 'dart:async';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tv_friso_screen/data_model/j_value.dart';
import 'package:tv_friso_screen/utils/phone_info_utils.dart';
import 'package:tv_friso_screen/utils/result_check_utils.dart';
import 'package:tv_friso_screen/utils/share_pre_utils.dart';
import 'package:tv_friso_screen/widget/map.dart';
import 'package:tv_friso_screen/widget/marquee_widget.dart';
import 'package:tv_friso_screen/widget/option_gridview.dart';

import 'data_model/home_info.dart';
import 'data_model/k_value.dart';
import 'login_page_phone_pad.dart';
import 'model/response_with_object.dart';
import 'net/api_address.dart';
import 'net/data_helper.dart';
import 'net/http_manager.dart';

class HomePagePhone extends StatefulWidget {
  const HomePagePhone({super.key});

  @override
  State<HomePagePhone> createState() => _HomePagePhoneState();
}

class _HomePagePhoneState extends State<HomePagePhone> {
  var scrollController = ScrollController();

  // 组件ListView的实例对象
  ScrollController autoScontroller = ScrollController();
  Timer? timer;
  Timer? timerPeriodic;
  Timer? mTimer; //页面定时刷新计时器
  Timer? downTimer; //右上角时分秒显示倒计时
  // 设置滚动的距离
  double offset = 0;
  HomeInfo? mHomeData;

  //全部数据 7个
  List<KValue> allItems = [];

  List<JValue> allJItems = [];
  List<String> zoneIndex = ["东区", "西区", "南区", "北区"];
  List<String> zoneEnIndex = [
    "East District",
    "West District",
    "South District",
    "North District"
  ];

  List<String> topIcons = [
    "assets/images/icon_one.png",
    "assets/images/icon_two.png",
    "assets/images/icon_three.png",
    "assets/images/icon_four.png",
    "assets/images/icon_five.png",
  ];

  var selectPIndex = -1; //点击选中的省份城市 集合下标
  var nowTime = "";

  late double width;
  late double height;

  late double scale;
  var currentLanguage = '';

  //全区销售数据统计（第二版单页面app接口）
  void getHomeData() async {
    var params = {};
    var formData = DataHelper.getBaseMapParams(params);
    var response =
        await HttpManager().get(ApiAddress.getMainData, query: formData);

    if (mounted) {
      if (response['data'] != null &&
          response['code'] == HttpManager.codeSuccess) {
        ResponseWithObject<HomeInfo> data =
            ResponseWithObject.fromJson(response as Map<String, dynamic>, (j) {
          if (j != null) {
            return HomeInfo.fromJson(j);
          } else {
            return j;
          }
        });
        if (data.code == HttpManager.codeSuccess && mounted) {
          //给首页赋值
          setState(() {
            mHomeData = data.data;
            allItems.clear();
            allJItems.clear();
            //首页头部今日数据
            if (null != mHomeData!.totalData) {
              allItems
                  .add(KValue("今日皇家(箱)", mHomeData!.totalData.prestigeGoods));
              allItems
                  .add(KValue("今日尊悦(箱)", mHomeData!.totalData.supremeGoods));
              allItems.add(
                  KValue("今日源悦(箱)", mHomeData!.totalData.dLGoods.toString()));
              allItems.add(KValue("今日旺玥(箱)", mHomeData!.totalData.immuGoods));
              // allItems.add(KValue("今日米粉(箱)", mHomeData!.totalData.goldGoods));
              //  allItems.add(KValue("今日活跃门店", mHomeData!.totalData.shopNumber));
              allItems
                  .add(KValue("皇家活跃", mHomeData!.totalData.prestigeShopNumber));
              allItems
                  .add(KValue("尊悦活跃", mHomeData!.totalData.supremeShopNumber));
              allItems.add(KValue("源悦活跃", mHomeData!.totalData.dLShopNumber));
              allItems.add(KValue("今日活跃门店", mHomeData!.totalData.shopNumber));

              //首页头部今日数据
              allJItems.add(JValue("Daily Prestige(Ctn)", "",
                  mHomeData!.totalData.prestigeGoods));
              allJItems.add(JValue("Daily Prestige Supre", "me(Ctn)",
                  mHomeData!.totalData.supremeGoods));
              allJItems.add(JValue(
                  "Daily Natura(Ctn)", "", mHomeData!.totalData.dLGoods));
              allJItems.add(JValue("Daily Prestige Kids", "(Ctn)",
                  mHomeData!.totalData.immuGoods));
              allJItems.add(JValue("Prestige Active", "(MTD/P3M)",
                  mHomeData!.totalData.prestigeShopNumber));
              allJItems.add(JValue("Prestige Supreme ", "Active(MTD/P3M)",
                  mHomeData!.totalData.supremeShopNumber));
              allJItems.add(JValue("Natura Active", "(MTD/P3M)",
                  mHomeData!.totalData.dLShopNumber));
              allJItems.add(JValue(
                  "Daily Active Store", "", mHomeData!.totalData.shopNumber));
            }
          });
        } else {
          ResultCheckUtils.checkResult(context, data.code, data.msg);
        }
      } else {
        // //token失效 退回至登录页
        // if (response['code'] == 20003) {}

        ResultCheckUtils.checkResult(
            context, response['code'], response['msg']);
      }
    }
  }

  void startTimer() {
    mTimer = Timer.periodic(const Duration(seconds: 15 * 60), (timer) {
      //每隔 15 分钟 刷新一次数据
      getHomeData();
    });
  }

  void countDownTimer() {
    downTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
      //每隔 1 秒钟 刷新一次时分秒
      setState(() {
        nowTime = PhoneInfoUtils.getTime();
      });
    });
  }

  @override
  void initState() {
    super.initState();
    currentLanguage = SharePreUtils.getLanguage();

    width = window.physicalSize.width;
    height = window.physicalSize.height;
    print(
        "屏幕宽高---------- $width $height  ${ScreenUtil().pixelRatio}  ${ScreenUtil().screenWidth} ${ScreenUtil().screenHeight}");

    scale = ScreenUtil().screenHeight > 414
        ? 0.4
        : (ScreenUtil().screenHeight > 411 ? 0.3 : 0.25);

    print("scale---------- $scale");

    getHomeData();

    timerPeriodic = Timer.periodic(const Duration(milliseconds: 100), (timer) {
      if (null != mHomeData && mHomeData!.saleDetail.isNotEmpty) {
        // 滚动监听事件
        if (autoScontroller.hasClients) {
          if (offset == 0) {
            // autoScontroller.jumpTo(offset);

            autoScontroller.animateTo(offset,
                duration: const Duration(milliseconds: 100),
                curve: Curves.linear);

            Future.delayed(const Duration(seconds: 2), () {
              offset++;

              // autoScontroller.animateTo(offset,
              //     duration: const Duration(milliseconds: 100),
              //     curve: Curves.linear);
            });
          } else if (offset > 0) {
            // autoScontroller.jumpTo(offset);
            autoScontroller.animateTo(offset - 1,
                duration: const Duration(milliseconds: 100),
                curve: Curves.linear);

            offset++;
          }
        }
      }
    });

    autoScontroller.addListener(() {
      if (null != mHomeData && mHomeData!.saleDetail.isNotEmpty) {
        if (autoScontroller.position.pixels <= 0) {
        } else if (autoScontroller.position.pixels >=
            autoScontroller.position.maxScrollExtent) {
          // sleep(const Duration(seconds: 1));
          setState(() {
            offset = 0;
          });
        }
      }
    });

    //定时器 15分钟 刷新一次首页数据
    startTimer();

    countDownTimer();
  }

  @override
  void dispose() {
    super.dispose();
    timer?.cancel();
    timerPeriodic?.cancel();
    autoScontroller.dispose();

    mTimer?.cancel();
    downTimer?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: currentLanguage == "zh"
          ? Container(
              width: double.infinity,
              height: double.infinity,
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(
                    "assets/images/icon_bg_back.png",
                  ),
                  fit: BoxFit.fill,
                ),
              ),
              child: Stack(
                children: [
                  GestureDetector(
                    onTap: () {
                      showLoginOutDialog(context);
                    },
                    child: Container(
                      margin: EdgeInsets.only(top: 15.w, left: 45.w),
                      child: Container(
                        padding: EdgeInsets.only(
                            left: 20.w, right: 20.w, top: 15.w, bottom: 15.w),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.w),
                          border: Border.all(
                            color: const Color.fromRGBO(3, 90, 168, 1),
                            width: 1.w,
                          ),
                        ),
                        child: Text(
                          "退出登录",
                          style: TextStyle(
                            color: const Color(0xFF1ED2FF),
                            fontSize: 18.sp,
                            fontWeight: FontWeight.w500,
                          ),
                          textAlign: TextAlign.center,
                        ),
                      ),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      bottom: scale <= 0.3 ? 70.w : 90.w,
                      top: scale <= 0.3 ? 100.w : 130.w,
                      left: 70.w,
                      right: 55.w,
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 2,
                          child: Column(
                            children: [
                              /*今日数据信息*/
                              Container(
                                child: allItems.isEmpty
                                    ? Container()
                                    : OptionGridView(
                                        itemCount: allItems.length,
                                        rowCount: 4,
                                        mainAxisSpacing: 5,
                                        crossAxisSpacing: 5,
                                        itemBuilder:
                                            (BuildContext context, int index) {
                                          return Container(
                                            alignment: Alignment.center,
                                            padding: EdgeInsets.all(10.w),
                                            decoration: BoxDecoration(
                                              borderRadius: BorderRadius.all(
                                                Radius.circular(5.w),
                                              ),
                                              border: Border.all(
                                                color: const Color(0xFF829EEE),
                                                width: 1.w,
                                              ),
                                            ),
                                            child: Column(
                                              children: [
                                                Row(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.center,
                                                  mainAxisAlignment:
                                                      MainAxisAlignment.center,
                                                  children: [
                                                    Text(
                                                      allItems[index].name,
                                                      maxLines: 1,
                                                      overflow:
                                                          TextOverflow.ellipsis,
                                                      style: TextStyle(
                                                        color: const Color(
                                                            0xFF1ED2FF),
                                                        fontSize: 16.sp,
                                                        fontWeight:
                                                            FontWeight.bold,
                                                      ),
                                                    ),
                                                    Visibility(
                                                      visible: allItems[index]
                                                              .name
                                                              .contains(
                                                                  "皇家活跃") ||
                                                          allItems[index]
                                                              .name
                                                              .contains(
                                                                  "源悦活跃") ||
                                                          allItems[index]
                                                              .name
                                                              .contains("尊悦活跃"),
                                                      child: Text(
                                                        "(MTD/P3M)",
                                                        maxLines: 1,
                                                        overflow: TextOverflow
                                                            .ellipsis,
                                                        style: TextStyle(
                                                          color: const Color(
                                                              0xFF1ED2FF),
                                                          fontSize: 14.sp,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ),
                                                  ],
                                                  //(MTD/P3M)
                                                ),
                                                SizedBox(
                                                  height: 10.w,
                                                ),
                                                Text(
                                                  allItems[index].value,
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFCA9A),
                                                    fontSize: 16.sp,
                                                    fontWeight: FontWeight.bold,
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: 5.w,
                                                ),
                                              ],
                                            ),
                                          );
                                        },
                                        scrollController: scrollController,
                                      ),
                              ),
                              underline(20.w, 0.w, 10.w, 30.w),
                              /*中国地图*/
                              Container(
                                alignment: Alignment.centerLeft,
                                child: Stack(
                                  children: [
                                    Text(
                                      "销售覆盖区域",
                                      style: TextStyle(
                                        color: Colors.white,
                                        fontSize: 26.sp,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                    Container(
                                      alignment: Alignment.center,
                                      width: double.infinity,
                                      child: Stack(
                                        children: [
                                          Container(
                                            width: double.infinity,
                                            alignment: Alignment.centerRight,
                                            margin: EdgeInsets.only(
                                                top: 150.w, right: 25.w),
                                            child: Text(
                                              selectPIndex == -1
                                                  ? ""
                                                  : "${mHomeData!.salesRegion[selectPIndex].pname}: ${mHomeData!.salesRegion[selectPIndex].nums}",
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 18.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                              textAlign: TextAlign.end,
                                            ),
                                          ),
                                          Container(
                                            width: double.infinity,
                                            alignment: Alignment.center,
                                            child: MapWidget(
                                              /* initScaleX: width == 1980 ? 0.3 : 0.25,
                                  initScaleY: height == 1080 ? 0.3 : 0.25,*/

                                              initScaleX: scale,
                                              initScaleY: scale,
                                              callBack: (String name) {
                                                if (null != mHomeData &&
                                                    mHomeData!.salesRegion
                                                        .isNotEmpty) {
                                                  for (var i = 0;
                                                      i <
                                                          mHomeData!.salesRegion
                                                              .length;
                                                      i++) {
                                                    if (mHomeData!
                                                        .salesRegion[i].pname
                                                        .contains(name)) {
                                                      setState(() {
                                                        selectPIndex = i;
                                                      });
                                                      break;
                                                    }
                                                  }
                                                }
                                              },
                                            ),
                                          ),
                                          Positioned(
                                            left: 0,
                                            bottom: 0,
                                            child: Text(
                                              "实时销售明细",
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 22.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                flex: 1,
                                child: Container(
                                  alignment: Alignment.centerLeft,
                                  margin: EdgeInsets.only(
                                    top: 15.w,
                                  ),
                                  padding: EdgeInsets.only(
                                    top: 20.w,
                                    left: 35.w,
                                    bottom: 10.w,
                                  ),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.all(
                                      Radius.circular(10.w),
                                    ),
                                    border: Border.all(
                                      color: const Color(0xFF829EEE),
                                      width: 1.w,
                                    ),
                                  ),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: null == mHomeData ||
                                                mHomeData!.saleDetail.isEmpty
                                            ? Container()
                                            : ListView.builder(
                                                shrinkWrap: true,
                                                itemCount: mHomeData!
                                                    .saleDetail.length,
                                                scrollDirection: Axis.vertical,
                                                controller: autoScontroller,
                                                itemBuilder:
                                                    (BuildContext context,
                                                        int index) {
                                                  var data = mHomeData!
                                                      .saleDetail[index];
                                                  return Container(
                                                    margin: EdgeInsets.only(
                                                        bottom: 15.w,
                                                        right: 35.w),
                                                    child: Row(
                                                      children: [
                                                        Text(
                                                          data.date,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        SizedBox(
                                                          width: 15.w,
                                                        ),
                                                        Text(
                                                          data.time,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        SizedBox(
                                                          width: 15.w,
                                                        ),
                                                        Text(
                                                          data.shopName,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        Expanded(
                                                          child: Text(
                                                            data.regionAddress,
                                                            textAlign:
                                                                TextAlign.end,
                                                            style: TextStyle(
                                                              color: const Color(
                                                                  0xFF1ED2FF),
                                                              fontSize: 18.sp,
                                                              fontWeight:
                                                                  FontWeight
                                                                      .bold,
                                                            ),
                                                          ),
                                                        ),
                                                      ],
                                                    ),
                                                  );
                                                },
                                              ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        Expanded(
                          flex: 3,
                          child: Column(
                            children: [
                              Expanded(
                                flex: 2,
                                child: Container(
                                  width: double.infinity,
                                  margin:
                                      EdgeInsets.only(left: 20.w, right: 10.w),
                                  padding: EdgeInsets.only(
                                    bottom: 10.w,
                                  ),
                                  color: const Color(0x260085F7),
                                  child: mHomeData == null
                                      ? Container()
                                      : Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            //东西南北
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneEast, 0),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneWest, 1),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneSouth, 2),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneNorth, 3),
                                            ),
                                          ],
                                        ),
                                ),
                              ),
                              Expanded(
                                flex: 1,
                                child: Container(
                                  margin: EdgeInsets.only(
                                      bottom: 0.w, top: 5.w, right: 10.w),
                                  padding:
                                      EdgeInsets.only(left: 20.w, right: 20.w),
                                  child: Row(
                                    children: [
                                      Expanded(
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            underline(0.w, 0.w, 10.w, 10.w),
                                            Row(
                                              children: [
                                                Image.asset(
                                                  "assets/images/icon_trangle.png",
                                                  width: 14.w,
                                                  height: 29.w,
                                                ),
                                                SizedBox(
                                                  width: 15.w,
                                                ),
                                                Text(
                                                  "本月Top5销售(省份)",
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFFFFF),
                                                    fontSize: 24.sp,
                                                    fontWeight: FontWeight.bold,
                                                  ),
                                                ),
                                              ],
                                            ),
                                            underline(15.w, 0.w, 0, 10.w),
                                            Expanded(
                                              child: Container(
                                                margin:
                                                    EdgeInsets.only(top: 20.w),
                                                padding: EdgeInsets.only(
                                                    left: 20.w,
                                                    top: 16.w,
                                                    right: 20.w,
                                                    bottom: 15.w),
                                                decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.all(
                                                    Radius.circular(10.w),
                                                  ),
                                                  border: Border.all(
                                                    color:
                                                        const Color(0xFF829EEE),
                                                    width: 1.w,
                                                  ),
                                                ),
                                                child: mHomeData == null ||
                                                        mHomeData!.saleProvince
                                                            .isEmpty
                                                    ? Container()
                                                    : ListView.builder(
                                                        shrinkWrap: true,
                                                        itemCount: mHomeData!
                                                            .saleProvince
                                                            .length,
                                                        scrollDirection:
                                                            Axis.vertical,
                                                        itemBuilder:
                                                            (BuildContext
                                                                    context,
                                                                int index) {
                                                          return Container(
                                                            margin:
                                                                EdgeInsets.only(
                                                                    bottom:
                                                                        15.w,
                                                                    right:
                                                                        35.w),
                                                            child: Row(
                                                              crossAxisAlignment:
                                                                  CrossAxisAlignment
                                                                      .center,
                                                              mainAxisAlignment:
                                                                  MainAxisAlignment
                                                                      .center,
                                                              children: [
                                                                Image.asset(
                                                                  topIcons[
                                                                      index],
                                                                  width: 18.w,
                                                                  height: 24.w,
                                                                ),
                                                                SizedBox(
                                                                  width: 15.w,
                                                                ),
                                                                Expanded(
                                                                  child: Text(
                                                                    // "浙江省宁波市余姚市",
                                                                    mHomeData!
                                                                        .saleProvince[
                                                                            index]
                                                                        .regionProvince,
                                                                    textAlign:
                                                                        TextAlign
                                                                            .left,
                                                                    style:
                                                                        TextStyle(
                                                                      color: const Color(
                                                                          0xFF1ED2FF),
                                                                      fontSize:
                                                                          18.sp,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .bold,
                                                                    ),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          );
                                                        },
                                                      ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                      SizedBox(
                                        width: 45.w,
                                      ),
                                      Expanded(
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            underline(0.w, 0.w, 10.w, 10.w),
                                            Row(
                                              children: [
                                                Image.asset(
                                                  "assets/images/icon_trangle.png",
                                                  width: 14.w,
                                                  height: 29.w,
                                                ),
                                                SizedBox(
                                                  width: 15.w,
                                                ),
                                                Text(
                                                  "本月Top5销售(城市)",
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFFFFF),
                                                    fontSize: 24.sp,
                                                    fontWeight: FontWeight.bold,
                                                  ),
                                                ),
                                              ],
                                            ),
                                            underline(15.w, 0.w, 0, 10.w),
                                            Expanded(
                                              child: Container(
                                                width: double.infinity,
                                                margin:
                                                    EdgeInsets.only(top: 20.w),
                                                padding: EdgeInsets.only(
                                                    left: 20.w,
                                                    top: 16.w,
                                                    right: 20.w,
                                                    bottom: 15.w),
                                                decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.all(
                                                    Radius.circular(10.w),
                                                  ),
                                                  border: Border.all(
                                                    color:
                                                        const Color(0xFF829EEE),
                                                    width: 1.w,
                                                  ),
                                                ),
                                                child: mHomeData == null ||
                                                        mHomeData!
                                                            .saleCity.isEmpty
                                                    ? Container()
                                                    : ListView.builder(
                                                        shrinkWrap: true,
                                                        itemCount: mHomeData!
                                                            .saleCity.length,
                                                        scrollDirection:
                                                            Axis.vertical,
                                                        itemBuilder:
                                                            (BuildContext
                                                                    context,
                                                                int index) {
                                                          return Container(
                                                            margin:
                                                                EdgeInsets.only(
                                                                    bottom:
                                                                        15.w,
                                                                    right:
                                                                        35.w),
                                                            child: Row(
                                                              children: [
                                                                Image.asset(
                                                                  // "assets/images/icon_one.png",
                                                                  topIcons[
                                                                      index],
                                                                  width: 18.w,
                                                                  height: 24.w,
                                                                ),
                                                                SizedBox(
                                                                  width: 15.w,
                                                                ),
                                                                Expanded(
                                                                  child: Text(
                                                                    // "浙江省宁波市余姚市",
                                                                    mHomeData!
                                                                        .saleCity[
                                                                            index]
                                                                        .regionProvince,
                                                                    textAlign:
                                                                        TextAlign
                                                                            .left,
                                                                    style:
                                                                        TextStyle(
                                                                      color: const Color(
                                                                          0xFF1ED2FF),
                                                                      fontSize:
                                                                          18.sp,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .bold,
                                                                    ),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          );
                                                        },
                                                      ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(top: 20.w, right: 30.w),
                    height: 100.w,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Text(
                          nowTime,
                          style: TextStyle(
                            color: const Color(0xFFBDE1FF),
                            fontSize: 28.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(
                          width: 20.w,
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              getWeekDay(),
                              style: TextStyle(
                                color: const Color(0xFFBDE1FF),
                                fontSize: 24.sp,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            Text(
                              PhoneInfoUtils.getDate(),
                              style: TextStyle(
                                color: const Color(0xFFBDE1FF),
                                fontSize: 24.sp,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Positioned(
                    left: 180.w,
                    top: 16.w,
                    child: Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.w),
                          border: Border.all(
                            color: const Color.fromRGBO(3, 90, 168, 1),
                            width: 1.w, // 边框宽度
                          )),
                      child: Row(
                        children: [
                          GestureDetector(
                            onTap: () {
                              SharePreUtils.setLanguage("zh");
                              setState(() {
                                currentLanguage = "zh";
                              });
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 15.w,
                                  bottom: 15.w),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.w),
                                color: currentLanguage == "zh"
                                    ? const Color.fromRGBO(30, 210, 255, 1)
                                    : Colors.transparent,
                              ),
                              child: Text(
                                "中文",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  color: currentLanguage == "zh"
                                      ? const Color.fromRGBO(8, 42, 51, 1)
                                      : const Color.fromRGBO(30, 210, 255, 1),
                                  fontSize: 18.sp,
                                  fontWeight: FontWeight.normal,
                                ),
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              SharePreUtils.setLanguage("en");
                              setState(() {
                                currentLanguage = "en";
                              });
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 15.w,
                                  bottom: 15.w),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.w),
                                color: currentLanguage == "en"
                                    ? const Color.fromRGBO(30, 210, 255, 1)
                                    : Colors.transparent,
                              ),
                              child: Text(
                                "English",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  color: currentLanguage == "en"
                                      ? const Color.fromRGBO(8, 42, 51, 1)
                                      : const Color.fromRGBO(30, 210, 255, 1),
                                  fontSize: 18.sp,
                                  fontWeight: FontWeight.normal,
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            )
          : Container(
              width: double.infinity,
              height: double.infinity,
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage(
                    "assets/images/icon_phone_main_en_back.png",
                  ),
                  fit: BoxFit.fill,
                ),
              ),
              child: Stack(
                children: [
                  GestureDetector(
                    onTap: () {
                      showLoginOutDialog(context);
                    },
                    child: Container(
                      margin: EdgeInsets.only(top: 15.w, left: 45.w),
                      child: Container(
                        padding: EdgeInsets.only(
                            left: 20.w, right: 20.w, top: 15.w, bottom: 15.w),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.w),
                          border: Border.all(
                            color: const Color.fromRGBO(3, 90, 168, 1),
                            width: 1.w,
                          ),
                        ),
                        child: Text(
                          "Log out",
                          style: TextStyle(
                            color: const Color(0xFF1ED2FF),
                            fontSize: 18.sp,
                            fontWeight: FontWeight.w500,
                          ),
                          textAlign: TextAlign.center,
                        ),
                      ),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(
                      bottom: scale <= 0.3 ? 70.w : 90.w,
                      top: scale <= 0.3 ? 100.w : 130.w,
                      left: 15.w,
                      right: 0.w,
                    ),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          flex: 2,
                          child: Column(
                            children: [
                              /*今日数据信息*/
                              Container(
                                child: allJItems.isEmpty
                                    ? Container()
                                    : OptionGridView(
                                        itemCount: allItems.length,
                                        rowCount: 4,
                                        mainAxisSpacing: 5,
                                        crossAxisSpacing: 5,
                                        itemBuilder:
                                            (BuildContext context, int index) {
                                          return Container(
                                            alignment: Alignment.center,
                                            // padding: EdgeInsets.all(10.w),
                                            height: 80.w,
                                            decoration: BoxDecoration(
                                              borderRadius: BorderRadius.all(
                                                Radius.circular(5.w),
                                              ),
                                              border: Border.all(
                                                color: const Color(0xFF829EEE),
                                                width: 1.w,
                                              ),
                                            ),
                                            child: Column(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.center,
                                              children: [
                                                Text(
                                                  allJItems[index].name,
                                                  maxLines: 1,
                                                  overflow:
                                                      TextOverflow.ellipsis,
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFF1ED2FF),
                                                    fontSize: 16.sp,
                                                    fontWeight: FontWeight.bold,
                                                  ),
                                                ),
                                                Visibility(
                                                  visible: allJItems[index]
                                                      .unit
                                                      .isNotEmpty,
                                                  child: Text(
                                                    allJItems[index].unit,
                                                    // maxLines: 1,
                                                    overflow:
                                                        TextOverflow.ellipsis,
                                                    style: TextStyle(
                                                      color: const Color(
                                                          0xFF1ED2FF),
                                                      fontSize: 12.sp,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: 5.w,
                                                ),
                                                Text(
                                                  allJItems[index].value,
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFCA9A),
                                                    fontSize: 16.sp,
                                                    fontWeight: FontWeight.bold,
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: 5.w,
                                                ),
                                              ],
                                            ),
                                          );
                                        },
                                        scrollController: scrollController,
                                      ),
                              ),
                              underline(20.w, 0.w, 10.w, 30.w),
                              /*中国地图*/
                              Container(
                                alignment: Alignment.centerLeft,
                                child: Stack(
                                  children: [
                                    /*Text(
                                "销售覆盖区域",
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 26.sp,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),*/
                                    Row(
                                      children: [
                                        SizedBox(
                                          width: 11.w,
                                        ),
                                        Image.asset(
                                          "assets/images/icon_trangle.png",
                                          width: 14.w,
                                          height: 29.w,
                                        ),
                                        SizedBox(
                                          width: 10.w,
                                        ),
                                        Text(
                                          "Sales Coverage",
                                          style: TextStyle(
                                            color: const Color(0xFFFFFFFF),
                                            fontSize: 22.sp,
                                            fontWeight: FontWeight.w500,
                                          ),
                                        ),
                                      ],
                                    ),
                                    Container(
                                      alignment: Alignment.center,
                                      width: double.infinity,
                                      child: Stack(
                                        children: [
                                          Container(
                                            width: double.infinity,
                                            alignment: Alignment.centerRight,
                                            margin: EdgeInsets.only(
                                                top: 150.w, right: 25.w),
                                            child: Text(
                                              selectPIndex == -1
                                                  ? ""
                                                  : "${mHomeData!.salesRegion[selectPIndex].pname}: ${mHomeData!.salesRegion[selectPIndex].nums}",
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 18.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                              textAlign: TextAlign.end,
                                            ),
                                          ),
                                          Container(
                                            width: double.infinity,
                                            alignment: Alignment.center,
                                            child: MapWidget(
                                              initScaleX: scale,
                                              initScaleY: scale,
                                              callBack: (String name) {
                                                if (null != mHomeData &&
                                                    mHomeData!.salesRegion
                                                        .isNotEmpty) {
                                                  for (var i = 0;
                                                      i <
                                                          mHomeData!.salesRegion
                                                              .length;
                                                      i++) {
                                                    if (mHomeData!
                                                        .salesRegion[i].pname
                                                        .contains(name)) {
                                                      setState(() {
                                                        selectPIndex = i;
                                                      });
                                                      break;
                                                    }
                                                  }
                                                }
                                              },
                                            ),
                                          ),
                                          Positioned(
                                            left: 0,
                                            bottom: 0,
                                            child: Text(
                                              "Real-time Sales Details",
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 22.sp,
                                                fontWeight: FontWeight.w500,
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                flex: 1,
                                child: Container(
                                  alignment: Alignment.centerLeft,
                                  margin: EdgeInsets.only(
                                    top: 15.w,
                                  ),
                                  padding: EdgeInsets.only(
                                    top: 20.w,
                                    left: 35.w,
                                    bottom: 10.w,
                                  ),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.all(
                                      Radius.circular(10.w),
                                    ),
                                    border: Border.all(
                                      color: const Color(0xFF829EEE),
                                      width: 1.w,
                                    ),
                                  ),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: null == mHomeData ||
                                                mHomeData!.saleDetail.isEmpty
                                            ? Container()
                                            : ListView.builder(
                                                shrinkWrap: true,
                                                itemCount: mHomeData!
                                                    .saleDetail.length,
                                                scrollDirection: Axis.vertical,
                                                controller: autoScontroller,
                                                itemBuilder:
                                                    (BuildContext context,
                                                        int index) {
                                                  var data = mHomeData!
                                                      .saleDetail[index];
                                                  return Container(
                                                    margin: EdgeInsets.only(
                                                        bottom: 15.w,
                                                        right: 35.w),
                                                    child: Row(
                                                      children: [
                                                        Text(
                                                          data.date,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        SizedBox(
                                                          width: 15.w,
                                                        ),
                                                        Text(
                                                          data.time,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        SizedBox(
                                                          width: 15.w,
                                                        ),
                                                        Text(
                                                          data.shopName,
                                                          style: TextStyle(
                                                            color: const Color(
                                                                0xFF1ED2FF),
                                                            fontSize: 18.sp,
                                                            fontWeight:
                                                                FontWeight.bold,
                                                          ),
                                                        ),
                                                        Expanded(
                                                          child: Text(
                                                            data.regionAddress,
                                                            textAlign:
                                                                TextAlign.end,
                                                            style: TextStyle(
                                                              color: const Color(
                                                                  0xFF1ED2FF),
                                                              fontSize: 18.sp,
                                                              fontWeight:
                                                                  FontWeight
                                                                      .bold,
                                                            ),
                                                          ),
                                                        ),
                                                      ],
                                                    ),
                                                  );
                                                },
                                              ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        Expanded(
                          flex: 3,
                          child: Column(
                            children: [
                              Expanded(
                                flex: 2,
                                child: Container(
                                  width: double.infinity,
                                  margin:
                                      EdgeInsets.only(left: 20.w, right: 10.w),
                                  padding: EdgeInsets.only(
                                    bottom: 10.w,
                                  ),
                                  color: const Color(0x260085F7),
                                  child: mHomeData == null
                                      ? Container()
                                      : Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            //东西南北
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneEast, 0),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneWest, 1),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneSouth, 2),
                                            ),
                                            Expanded(
                                              child: zoneWidget(
                                                  mHomeData!.zoneNorth, 3),
                                            ),
                                          ],
                                        ),
                                ),
                              ),
                              Expanded(
                                flex: 1,
                                child: Container(
                                  margin: EdgeInsets.only(
                                      bottom: 0.w, top: 5.w, right: 10.w),
                                  padding:
                                      EdgeInsets.only(left: 20.w, right: 20.w),
                                  child: Row(
                                    children: [
                                      Expanded(
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            underline(0.w, 0.w, 10.w, 10.w),
                                            Row(
                                              children: [
                                                Image.asset(
                                                  "assets/images/icon_trangle.png",
                                                  width: 14.w,
                                                  height: 29.w,
                                                ),
                                                SizedBox(
                                                  width: 15.w,
                                                ),
                                                Text(
                                                  "MTD Sales Top5 (Province)",
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFFFFF),
                                                    fontSize: 22.sp,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ],
                                            ),
                                            underline(15.w, 0.w, 0, 10.w),
                                            Expanded(
                                              child: Container(
                                                margin:
                                                    EdgeInsets.only(top: 20.w),
                                                padding: EdgeInsets.only(
                                                    left: 20.w,
                                                    top: 16.w,
                                                    right: 20.w,
                                                    bottom: 15.w),
                                                decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.all(
                                                    Radius.circular(10.w),
                                                  ),
                                                  border: Border.all(
                                                    color:
                                                        const Color(0xFF829EEE),
                                                    width: 1.w,
                                                  ),
                                                ),
                                                child: mHomeData == null ||
                                                        mHomeData!.saleProvince
                                                            .isEmpty
                                                    ? Container()
                                                    : ListView.builder(
                                                        shrinkWrap: true,
                                                        itemCount: mHomeData!
                                                            .saleProvince
                                                            .length,
                                                        scrollDirection:
                                                            Axis.vertical,
                                                        itemBuilder:
                                                            (BuildContext
                                                                    context,
                                                                int index) {
                                                          return Container(
                                                            margin:
                                                                EdgeInsets.only(
                                                                    bottom:
                                                                        15.w,
                                                                    right:
                                                                        35.w),
                                                            child: Row(
                                                              crossAxisAlignment:
                                                                  CrossAxisAlignment
                                                                      .center,
                                                              mainAxisAlignment:
                                                                  MainAxisAlignment
                                                                      .center,
                                                              children: [
                                                                Image.asset(
                                                                  topIcons[
                                                                      index],
                                                                  width: 18.w,
                                                                  height: 24.w,
                                                                ),
                                                                SizedBox(
                                                                  width: 15.w,
                                                                ),
                                                                Expanded(
                                                                  child: Text(
                                                                    // "浙江省宁波市余姚市",
                                                                    mHomeData!
                                                                        .saleProvince[
                                                                            index]
                                                                        .regionProvince,
                                                                    textAlign:
                                                                        TextAlign
                                                                            .left,
                                                                    style:
                                                                        TextStyle(
                                                                      color: const Color(
                                                                          0xFF1ED2FF),
                                                                      fontSize:
                                                                          18.sp,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .w500,
                                                                    ),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          );
                                                        },
                                                      ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                      SizedBox(
                                        width: 45.w,
                                      ),
                                      Expanded(
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            underline(0.w, 0.w, 10.w, 10.w),
                                            Row(
                                              children: [
                                                Image.asset(
                                                  "assets/images/icon_trangle.png",
                                                  width: 14.w,
                                                  height: 29.w,
                                                ),
                                                SizedBox(
                                                  width: 15.w,
                                                ),
                                                Text(
                                                  "MTD Sales Top5 (City)",
                                                  style: TextStyle(
                                                    color:
                                                        const Color(0xFFFFFFFF),
                                                    fontSize: 22.sp,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                              ],
                                            ),
                                            underline(15.w, 0.w, 0, 10.w),
                                            Expanded(
                                              child: Container(
                                                width: double.infinity,
                                                margin:
                                                    EdgeInsets.only(top: 20.w),
                                                padding: EdgeInsets.only(
                                                    left: 20.w,
                                                    top: 16.w,
                                                    right: 20.w,
                                                    bottom: 15.w),
                                                decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.all(
                                                    Radius.circular(10.w),
                                                  ),
                                                  border: Border.all(
                                                    color:
                                                        const Color(0xFF829EEE),
                                                    width: 1.w,
                                                  ),
                                                ),
                                                child: mHomeData == null ||
                                                        mHomeData!
                                                            .saleCity.isEmpty
                                                    ? Container()
                                                    : ListView.builder(
                                                        shrinkWrap: true,
                                                        itemCount: mHomeData!
                                                            .saleCity.length,
                                                        scrollDirection:
                                                            Axis.vertical,
                                                        itemBuilder:
                                                            (BuildContext
                                                                    context,
                                                                int index) {
                                                          return Container(
                                                            margin:
                                                                EdgeInsets.only(
                                                                    bottom:
                                                                        15.w,
                                                                    right:
                                                                        35.w),
                                                            child: Row(
                                                              children: [
                                                                Image.asset(
                                                                  // "assets/images/icon_one.png",
                                                                  topIcons[
                                                                      index],
                                                                  width: 18.w,
                                                                  height: 24.w,
                                                                ),
                                                                SizedBox(
                                                                  width: 15.w,
                                                                ),
                                                                Expanded(
                                                                  child: Text(
                                                                    // "浙江省宁波市余姚市",
                                                                    mHomeData!
                                                                        .saleCity[
                                                                            index]
                                                                        .regionProvince,
                                                                    textAlign:
                                                                        TextAlign
                                                                            .left,
                                                                    style:
                                                                        TextStyle(
                                                                      color: const Color(
                                                                          0xFF1ED2FF),
                                                                      fontSize:
                                                                          18.sp,
                                                                      fontWeight:
                                                                          FontWeight
                                                                              .w500,
                                                                    ),
                                                                  ),
                                                                ),
                                                              ],
                                                            ),
                                                          );
                                                        },
                                                      ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(top: 20.w, right: 30.w),
                    height: 100.w,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Text(
                          nowTime,
                          style: TextStyle(
                            color: const Color(0xFFBDE1FF),
                            fontSize: 26.sp,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        SizedBox(
                          width: 20.w,
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              getWeekDay(),
                              style: TextStyle(
                                color: const Color(0xFFBDE1FF),
                                fontSize: 22.sp,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                            Text(
                              PhoneInfoUtils.getDate(),
                              style: TextStyle(
                                color: const Color(0xFFBDE1FF),
                                fontSize: 22.sp,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Positioned(
                    left: 180.w,
                    top: 16.w,
                    child: Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.w),
                          border: Border.all(
                            color: const Color.fromRGBO(3, 90, 168, 1),
                            width: 1.w, // 边框宽度
                          )),
                      child: Row(
                        children: [
                          GestureDetector(
                            onTap: () {
                              SharePreUtils.setLanguage("zh");
                              setState(() {
                                currentLanguage = "zh";
                              });
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 15.w,
                                  bottom: 15.w),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.w),
                                color: currentLanguage == "zh"
                                    ? const Color.fromRGBO(30, 210, 255, 1)
                                    : Colors.transparent,
                              ),
                              child: Text(
                                "中文",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  color: currentLanguage == "zh"
                                      ? const Color.fromRGBO(8, 42, 51, 1)
                                      : const Color.fromRGBO(30, 210, 255, 1),
                                  fontSize: 18.sp,
                                  fontWeight: FontWeight.normal,
                                ),
                              ),
                            ),
                          ),
                          GestureDetector(
                            onTap: () {
                              SharePreUtils.setLanguage("en");
                              setState(() {
                                currentLanguage = "en";
                              });
                            },
                            child: Container(
                              padding: EdgeInsets.only(
                                  left: 30.w,
                                  right: 30.w,
                                  top: 15.w,
                                  bottom: 15.w),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8.w),
                                color: currentLanguage == "en"
                                    ? const Color.fromRGBO(30, 210, 255, 1)
                                    : Colors.transparent,
                              ),
                              child: Text(
                                "English",
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                  color: currentLanguage == "en"
                                      ? const Color.fromRGBO(8, 42, 51, 1)
                                      : const Color.fromRGBO(30, 210, 255, 1),
                                  fontSize: 18.sp,
                                  fontWeight: FontWeight.normal,
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
    );
  }

  void showLoginOutDialog(BuildContext context) {
    showDialog(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return StatefulBuilder(
            builder: (BuildContext context, StateSetter setState) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Stack(
                children: [
                  Container(
                    alignment: Alignment.center,
                    width: 500.w,
                    height: 500.w,
                    margin: EdgeInsets.only(
                      left: 65.w,
                      right: 65.w,
                      top: 70.w,
                    ),
                    padding: EdgeInsets.only(left: 40.w, right: 40.w),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(20.w)),
                      image: const DecorationImage(
                        image: AssetImage("assets/images/icon_update_bg.png"),
                        fit: BoxFit.fill,
                      ),
                    ),
                    child: Column(
                      // crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          height: 60.w,
                        ),
                        Text(
                          "退出登录",
                          style: TextStyle(
                            fontSize: 32.sp,
                            color: const Color(0xFF00EEFF),
                            fontWeight: FontWeight.bold,
                            decoration: TextDecoration.none,
                          ),
                          textAlign: TextAlign.center,
                        ),
                        SizedBox(
                          height: 20.h,
                        ),
                        Text(
                          "确定要退出登录吗?",
                          softWrap: true,
                          style: TextStyle(
                            fontSize: 24.sp,
                            color: const Color(0xff8BD8DD),
                            decoration: TextDecoration.none,
                            fontWeight: FontWeight.normal,
                          ),
                          textAlign: TextAlign.start,
                        ),
                        const Spacer(),
                        Container(
                          margin: EdgeInsets.only(
                              left: 20.w, right: 20.w, bottom: 60.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              GestureDetector(
                                onTap: () {
                                  //回到登录页
                                  SharePreUtils.setToken("");
                                  Navigator.of(context).pushAndRemoveUntil(
                                      MaterialPageRoute(
                                          builder: (context) =>
                                              const LoginPhonePadPage()),
                                      (route) => false);
                                },
                                child: Container(
                                  padding: EdgeInsets.only(
                                      left: 40.w,
                                      right: 40.w,
                                      top: 20.w,
                                      bottom: 20.w),
                                  alignment: Alignment.center,
                                  decoration: const BoxDecoration(
                                    // borderRadius:
                                    //     BorderRadius.all(Radius.circular(20.w)),
                                    image: DecorationImage(
                                      image: AssetImage(
                                          "assets/images/icon_update_btn.png"),
                                      fit: BoxFit.fill,
                                    ),
                                  ),
                                  child: Text(
                                    "确定",
                                    style: TextStyle(
                                      fontSize: 28.sp,
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      decoration: TextDecoration.none,
                                    ),
                                  ),
                                ),
                              ),
                              GestureDetector(
                                onTap: () {
                                  Navigator.pop(context);
                                },
                                child: Container(
                                  padding: EdgeInsets.only(
                                      left: 40.w,
                                      right: 40.w,
                                      top: 20.w,
                                      bottom: 20.w),
                                  alignment: Alignment.center,
                                  decoration: const BoxDecoration(
                                    // borderRadius:
                                    //     BorderRadius.all(Radius.circular(20.w)),
                                    image: DecorationImage(
                                      image: AssetImage(
                                          "assets/images/icon_update_btn.png"),
                                      fit: BoxFit.fill,
                                    ),
                                  ),
                                  child: Text(
                                    "取消",
                                    style: TextStyle(
                                      fontSize: 28.sp,
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      decoration: TextDecoration.none,
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          );
        });
      },
    );
  }

  //走马灯效果
  MarqueeWidget buildMarqueeWidget(List<String> loopList) {
    ///上下轮播 安全提示
    return MarqueeWidget(
      //子Item构建器
      itemBuilder: (BuildContext context, int index) {
        String itemStr = loopList[index];
        //通常可以是一个 Text文本
        return Container(
          height: 45.h,
          padding: EdgeInsets.only(
            left: 15.w,
          ),
          alignment: Alignment.centerLeft,
          child: Text(
            itemStr,
            style: TextStyle(
              color: Colors.white,
              fontSize: 26.sp,
            ),
            softWrap: true,
            overflow: TextOverflow.ellipsis,
          ),
        );
      },
      //循环的提示消息数量
      count: loopList.length,
    );
  }

  Widget underline(double top, double left, double bottom, double mWidth) {
    return Container(
      margin: EdgeInsets.only(
        top: top,
        left: left,
        bottom: bottom,
      ),
      color: const Color(0xFF0F5FAF),
      width: double.infinity,
      height: 1.5.w,
      child: Stack(
        children: [
          Container(
            color: const Color(0xff00B7FE),
            width: mWidth,
            height: 2.w,
          ),
        ],
      ),
    );
  }

  Widget emptyWidget(double top, double left, double mWidth) {
    return Container(
      margin: EdgeInsets.only(
        top: top,
        left: left,
      ),
      color: const Color(0xff1ED2FF),
      width: 25.w,
      height: 2.w,
    );
  }

  //东西南北区
  Widget zoneWidget(Zone data, int index) {
    return currentLanguage == "zh"
        ? Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              underline(index == 0 ? 0.w : 5.w, 0.w, 5.w, 30.w),
              Row(
                children: [
                  SizedBox(
                    width: 11.w,
                  ),
                  Image.asset(
                    "assets/images/icon_trangle.png",
                    width: 14.w,
                    height: 29.w,
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Text(
                    zoneIndex[index],
                    style: TextStyle(
                      color: const Color(0xFFFFFFFF),
                      fontSize: 24.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 5.w,
              ),
              Row(
                children: [
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("今日皇家(箱)", data.prestigeGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("今日尊悦(箱)", data.supremeGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("今日源悦(箱)", data.dLGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  /*Expanded(
              child: zoneItem("今日米粉(箱)", data.goldGoods),
            ),
            SizedBox(
              width: 10.w,
            ),*/
                  Expanded(
                    child: zoneItem("今日旺玥(箱)", data.immuGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("今日活跃门店", data.shopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("皇家活跃", data.prestigeShopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneItem("源悦活跃", data.dLShopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  /* Expanded(
              child: zoneItem("米粉活跃", data.goldShopNumber),
            ),*/
                  // Expanded(
                  //   child: zoneItem("旺月活跃", data.immuShopNumber),
                  // ),
                  // SizedBox(
                  //   width: 10.w,
                  // ),
                ],
              ),
            ],
          )
        : Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              underline(index == 0 ? 0.w : 5.w, 0.w, 5.w, 30.w),
              Row(
                children: [
                  SizedBox(
                    width: 11.w,
                  ),
                  Image.asset(
                    "assets/images/icon_trangle.png",
                    width: 14.w,
                    height: 29.w,
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Text(
                    zoneEnIndex[index],
                    style: TextStyle(
                      color: const Color(0xFFFFFFFF),
                      fontSize: 20.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
              SizedBox(
                height: 10.w,
              ),
              Row(
                children: [
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem(
                        "Daily Prestige", "(Ctn)", data.prestigeGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem(
                        "Daily Prestige Supreme", "(Ctn)", data.supremeGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem("Daily Natura", "(Ctn)", data.dLGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem(
                        "Daily Prestige Kids", "(Ctn)", data.immuGoods),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child:
                        zoneEnItem("Daily Active Store", "", data.shopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem("Prestige Active", "(MTD/P3M)",
                        data.prestigeShopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                  Expanded(
                    child: zoneEnItem(
                        "Natura Active", "(MTD/P3M)", data.dLShopNumber),
                  ),
                  SizedBox(
                    width: 10.w,
                  ),
                ],
              ),
            ],
          );
  }

  Widget zoneItem(String title, String value) {
    return Container(
      alignment: Alignment.center,
      padding: EdgeInsets.all(10.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(5.w),
        ),
        border: Border.all(
          color: const Color(0xFF829EEE),
          width: 1.w,
        ),
      ),
      child: Column(
        children: [
          RichText(
            text: TextSpan(
              children: [
                TextSpan(
                  text: title,
                  style: TextStyle(
                    color: const Color(0xFF1ED2FF),
                    fontSize: 11.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                TextSpan(
                  text: title.contains("皇家活跃") ||
                          title.contains("源悦活跃") ||
                          title.contains("米粉活跃") ||
                          title.contains("旺月活跃")
                      ? "(MTD/P3M)"
                      : "",
                  style: TextStyle(
                    color: const Color(0xFF1ED2FF),
                    fontSize: 9.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: 5.w,
          ),
          value.isEmpty
              ? emptyWidget(0, 0, 0)
              : Text(
                  value,
                  style: TextStyle(
                    color: const Color(0xFFFFCA9A),
                    fontSize: 16.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
        ],
      ),
    );
  }

  Widget zoneEnItem(String title, String unit, String value) {
    return Container(
      alignment: Alignment.center,
      padding: EdgeInsets.symmetric(vertical: 5.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(5.w),
        ),
        border: Border.all(
          color: const Color(0xFF829EEE),
          width: 1.w,
        ),
      ),
      child: Column(
        children: [
          RichText(
            textAlign: TextAlign.center,
            text: TextSpan(
              children: [
                TextSpan(
                  text: title,
                  style: TextStyle(
                    color: const Color(0xFF1ED2FF),
                    fontSize: 11.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
          Text(
            unit,
            style: TextStyle(
              color: const Color(0xFF1ED2FF),
              fontSize: 9.sp,
              fontWeight: FontWeight.bold,
            ),
          ),
          SizedBox(
            height: 5.w,
          ),
          /*value.isEmpty
              ? emptyWidget(0, 0, 0)
              : Text(
                  value,
                  style: TextStyle(
                    color: const Color(0xFFFFCA9A),
                    fontSize: 16.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),*/

          Text(
            value,
            style: TextStyle(
              color: const Color(0xFFFFCA9A),
              fontSize: 16.sp,
              fontWeight: FontWeight.bold,
            ),
          ),
        ],
      ),
    );
  }

  //获取周几
  String getWeekDay() {
    DateTime now = DateTime.now(); // 获取当前日期和时间
    String weekDay;
    if (currentLanguage == "zh") {
      switch (now.weekday) {
        case DateTime.monday:
          weekDay = "星期一";
          break;
        case DateTime.tuesday:
          weekDay = "星期二";
          break;
        case DateTime.wednesday:
          weekDay = "星期三";
          break;
        case DateTime.thursday:
          weekDay = "星期四";
          break;
        case DateTime.friday:
          weekDay = "星期五";
          break;
        case DateTime.saturday:
          weekDay = "星期六";
          break;
        default:
          weekDay = "星期天";
          break;
      }
    } else {
      switch (now.weekday) {
        case DateTime.monday:
          weekDay = "Monday";
          break;
        case DateTime.tuesday:
          weekDay = "Tuesday";
          break;
        case DateTime.wednesday:
          weekDay = "Wednesday";
          break;
        case DateTime.thursday:
          weekDay = "Thursday";
          break;
        case DateTime.friday:
          weekDay = "Friday";
          break;
        case DateTime.saturday:
          weekDay = "Saturday";
          break;
        default:
          weekDay = "Sunday";
          break;
      }
    }

    return weekDay;
  }
}
